#!/bin/bash

# Generate vm1 public/private key pair into private keystore
echo Generating vm1 public private key pair
keytool -genkey -alias vm1private -keystore vm1.private -storetype JKS -keyalg rsa -dname "CN=FIB, OU=UPC, O=UPC, L=Barcelona, S=Catalonia, C=Spain" -storepass vm1pass -keypass vm1pass

# Generate vm2 public/private key pair into private keystore
echo Generating vm2 public private key pair
keytool -genkey -alias vm2private -keystore vm2.private -storetype JKS -keyalg rsa -dname "CN=FME, OU=UPC, O=UPC, L=Barcelona, S=Catalonia, C=Spain" -storepass vm2pass -keypass vm2pass

# Generate vm3 public/private key pair into private keystore
echo Generating vm3 public private key pair
keytool -genkey -alias vm3private -keystore vm3.private -storetype JKS -keyalg rsa -dname "CN=ESAII, OU=UPC, O=UPC, L=Barcelona, S=Catalonia, C=Spain" -storepass vm3pass -keypass vm3pass

# Generate vm4 public/private key pair into private keystore
echo Generating vm4 public private key pair
keytool -genkey -alias vm4private -keystore vm4.private -storetype JKS -keyalg rsa -dname "CN=AC, OU=UPC, O=UPC, L=Barcelona, S=Catalonia, C=Spain" -storepass vm4pass -keypass vm4pass

# Generate vm1 public/private key pair into private keystore
echo Generating vm5 public private key pair
keytool -genkey -alias vm5private -keystore vm5.private -storetype JKS -keyalg rsa -dname "CN=LSI, OU=UPC, O=UPC, L=Barcelona, S=Catalonia, C=Spain" -storepass vm5pass -keypass vm5pass

# Generate em public/private key pair
echo Generating em public private key pair
keytool -genkey -alias emprivate -keystore em.private -storetype JKS -keyalg rsa -dname "CN=pxCloud, OU=subgrup1, O=grup33, L=Barcelona, S=Catalonia, C=Spain" -storepass empass -keypass empass

# Generate mf public/private key pair into private keystore
echo Generating mf public private key pair
keytool -genkey -alias mfprivate -keystore mf.private -storetype JKS -keyalg rsa -dname "CN=pxCloud, OU=subgrup1, O=grup33, L=Barcelona, S=Catalonia, C=Spain" -storepass mfpass -keypass mfpass

# Export vm1 public key and import it into public keystore
echo Generating vm1 public key file
keytool -export -alias vm1private -keystore vm1.private -file temp.key -storepass vm1pass
keytool -import -noprompt -alias vm1public -keystore vm.public -file temp.key -storepass public
rm -f temp.key

# Export vm2 public key and import it into public keystore
echo Generating vm2 public key file
keytool -export -alias vm2private -keystore vm2.private -file temp.key -storepass vm2pass
keytool -import -noprompt -alias vm2public -keystore vm.public -file temp.key -storepass public
rm -f temp.key

# Export vm3 public key and import it into public keystore
echo Generating vm3 public key file
keytool -export -alias vm3private -keystore vm3.private -file temp.key -storepass vm3pass
keytool -import -noprompt -alias vm3public -keystore vm.public -file temp.key -storepass public
rm -f temp.key

# Export vm4 public key and import it into public keystore
echo Generating vm4 public key file
keytool -export -alias vm4private -keystore vm4.private -file temp.key -storepass vm4pass
keytool -import -noprompt -alias vm4public -keystore vm.public -file temp.key -storepass public
rm -f temp.key

# Export vm5 public key and import it into public keystore
echo Generating vm5 public key file
keytool -export -alias vm5private -keystore vm5.private -file temp.key -storepass vm5pass
keytool -import -noprompt -alias vm5public -keystore vm.public -file temp.key -storepass public
rm -f temp.key

# Export em public key and import it into public keystore
echo Generating em public key file
keytool -export -alias emprivate -keystore em.private -file temp.key -storepass empass
keytool -import -noprompt -alias empublic -keystore em.public -file temp.key -storepass public
rm -f temp.key

# Export mf public key and import it into public keystore
echo Generating mf public key file
keytool -export -alias mfprivate -keystore mf.private -file temp.key -storepass mfpass
keytool -import -noprompt -alias mfpublic -keystore mf.public -file temp.key -storepass public
rm -f temp.key
